﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.ModelBinding;
using OUSMS.AppLogic.BusinessLogicLayer;
using OUSMS.AppLogic.DataAccessLayer;
using OUSMS.Helpers;
using System.IO;
namespace OUSMS
{
    public partial class DownloadFile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                MotionFilesBLL motionFileBLL = new MotionFilesBLL();
                MotionFiles motionFileEntity = motionFileBLL.GetMotionFileByID(Convert.ToInt64(Request.QueryString["MID"]));
                string filePath = Request.PhysicalApplicationPath + "MotionFiles/" + Request.QueryString["MID"] + Path.GetExtension(motionFileEntity.FileName);
                FileInfo info = new FileInfo(filePath);
                long fileSize = info.Length;
                Response.Clear();
                Response.ContentType = StringUtility.MimeTypes[Path.GetExtension(motionFileEntity.FileName).Substring(1, Path.GetExtension(motionFileEntity.FileName).Length - 1)];
                Response.AddHeader("Content-Disposition", "attachement;filename=" + HttpContext.Current.Server.UrlEncode(motionFileEntity.FileName));
                //指定文件大小 
                Response.AddHeader("Content-Length", fileSize.ToString());
                Response.TransmitFile(filePath, 0, fileSize);
                Response.End();
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
            }
        }
    }
}